package com.woniuxy.vuecli.consumer;

import com.rabbitmq.client.Channel;
import com.woniuxy.vuecli.entity.EmailCode;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author author
 * @Create 2024-02-29 19:15
 */
@Component
public class RabbitConsumer {

    @RabbitListener(queues = "queueemail")
    public void receiveEmail(EmailCode emailCode, Message message, Channel channel) throws IOException {
        //邮件队列消费者，执行发邮件操作
//        MailUtil.send(emailCode.getEmail(), "xxx网站找回密码", "找回密码邮箱验证码:"+emailCode.getCode(),false);
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("发送邮件成功");
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

}
